/*===========================================================================================================================
	Wolf Prop Protection
		By Goluch
			DO NOT UPLOAD TO GARRYSMOD.ORG
			
			
	Section: Commands
===========================================================================================================================*/
WPP.Commands = { };

/*===========================================================================================================================
	Name: WPP.Command
	Purpose: Creates the WPP main command.
	Author: Goluch
===========================================================================================================================*/
function WPP.Command(Player,Line,Args)
	Command = Args[1];
	table.remove(Args,1);
	if ( !WPP.Commands[Command] ) then
		return;
	end
	
	local B,S = pcall(WPP.Commands[Command],WPP,Player,unpack(Args));
	//PrintTable(Args);
	if ( !B ) then
		print("Error with WPP concommand ",Command," ",S);
	end
end

concommand.Add("wpp",WPP.Command);

/*===========================================================================================================================
	WPP Command: trust
	Purpose: Sets player trust.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:trust(Player,Target,Index,Bool)
	if ( !WPP:IsValidAction(tonumber(Index)) ) then
		return;
	end
	
	if ( tonumber(Target) == -1 ) then
		WPP:SetTrustGlobal(Player,tonumber(Index),tobool(tonumber(Bool)));
	else
		Target = player.GetByID(tonumber(Target));
		if ( !Target ) or ( !Target:IsPlayer() ) then
			return;
		end
		
		WPP:SetTrust(Player,Target,tonumber(Index),tobool(tonumber(Bool)));
	end
	
end

/*===========================================================================================================================
	WPP Command: share
	Purpose: Sets objects share.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:share(Player,EntityID,Index,Bool)
	local Entity = Entity( EntityID );
	if ( !Entity ) or ( !Entity:IsValid() ) then
		return;
	end
	
	if ( !WPP:IsOwned(Entity) ) or ( !WPP:GetOwner(Entity,Player) ) then
		return;
	end
	
	WPP:SetShare(Entity,tonumber(Index),tobool(tonumber(Bool)));
end

/*===========================================================================================================================
	WPP Command: cleanup
	Purpose: cleans up a players objects.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:cleanup(Player)
	WPP:CleanUp( Player:SteamID() );
end

/*===========================================================================================================================
	WPP Command: wipe
	Purpose: Clears a players actions.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:wipe(Player)
	WPP:WipeTrust( Player );
end

/*===========================================================================================================================
	WPP Command: cleanupplayer
	Purpose: Clears a players objects for admins.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:cleanupplayer(Player,Target)
	if ( !Player:IsAdmin() ) then
		return;
	end
	
	Target = player.GetByUniqueID(Target);
	if ( !Target ) or ( !Target:IsPlayer() ) then
		return;
	end
	
	if ( Target:IsSuperAdmin() ) and ( Target != Player ) then
		return;
	end
	
	WPP:CleanUp( Target:SteamID() );
end

/*===========================================================================================================================
	WPP Command: cleanupplayer
	Purpose: Clears a players objects for admins.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:cleanupdisconected(Player)
	if ( !Player:IsAdmin() ) then
		return;
	end
	
	for _,Ent in pairs ( ents.GetAll() ) do
		if ( IsValid(Ent) ) and ( WPP:IsOwned(Ent) ) then
			local Owner = WPP:GetOwner(Ent)
			if ( !Owner ) or ( !Owner:IsValid() ) then
				Ent:Remove()
			end
		end
	end
	
end

/*===========================================================================================================================
	WPP Command: noclip
	Purpose: toggles anti noclip.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:noclip(Player)
	if ( !Player:IsSuperAdmin() ) then
		return;
	end
	
	local Value = 1;
	if ( GetConVarNumber("wpp_anti_noclip") > 0 ) then
		Value = 0
	end
	
	RunConsoleCommand("wpp_anti_noclip",Value);
end

/*===========================================================================================================================
	WPP Command: damage
	Purpose: toggles anti damage.
	Author: Goluch
===========================================================================================================================*/
function WPP.Commands:damage(Player)
	if ( !Player:IsSuperAdmin() ) then
		return;
	end
	
	local Value = 1;
	if ( GetConVarNumber("wpp_stop_damage") > 0 ) then
		Value = 0
	end
	
	RunConsoleCommand("wpp_stop_damage",Value);
end